/*
     Copyright 2007 Joseph M. Ferner

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using NUnit.Framework;

namespace OpenServers.Net.Common.FileSystem.Virtual {
    [TestFixture]
    public class VirtualFileSystemObjectTest {
        [Test]
        public void TestLastModified() {
            MockVirtualFileSystemObject fso = new MockVirtualFileSystemObject(null, "a");
            fso.LastModified = new DateTime(1977, 10, 30);
            Assert.AreEqual(new DateTime(1977, 10, 30), fso.LastModified);
        }

        [Test]
        public void TestReadOnly() {
            MockVirtualFileSystemObject fso = new MockVirtualFileSystemObject(null, "a");
            fso.ReadOnly = true;
            Assert.AreEqual(true, fso.ReadOnly);
        }

        [Test]
        [ExpectedException(ExceptionType = typeof(NotImplementedException))]
        public void TestMoveTo() {
            MockVirtualFileSystemObject fso = new MockVirtualFileSystemObject(null, "a");
            fso.MoveTo(null);
        }

        [Test]
        [ExpectedException(ExceptionType = typeof(NotImplementedException))]
        public void TestDeleteNoParent() {
            MockVirtualFileSystemObject fso = new MockVirtualFileSystemObject(null, "a");
            fso.Delete();
        }

        [Test]
        public void TestDelete() {
            VirtualDirectory dir = new VirtualDirectory(null, "root");
            MockVirtualFileSystemObject fso = new MockVirtualFileSystemObject(dir, "a");
            dir.GetItems().Add(fso);
            Assert.AreEqual(1, dir.GetItems().Count);
            fso.Delete();
            Assert.AreEqual(0, dir.GetItems().Count);
        }

        public class MockVirtualFileSystemObject : VirtualFileSystemObject {
            public MockVirtualFileSystemObject(IDirectory parent, string name)
                : base(parent, name) {
            }
        }
    }
}
